
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Hive基础 · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" >
            
                <span>
            
                    
                    Hadoop总结
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../chapter1/hadoopBase.html">
            
                <a href="../chapter1/hadoopBase.html">
            
                    
                    Hadoop基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../chapter1/Hadoop性能优化.html">
            
                <a href="../chapter1/Hadoop性能优化.html">
            
                    
                    Hadoop性能优化
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../chapter1/Hadoop故障处理.html">
            
                <a href="../chapter1/Hadoop故障处理.html">
            
                    
                    Hadoop故障处理
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" >
            
                <span>
            
                    
                    Flume总结
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../chapter2/FlumeBase.html">
            
                <a href="../chapter2/FlumeBase.html">
            
                    
                    Flume基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" >
            
                <span>
            
                    
                    Hive总结
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.4.1" data-path="HiveBase.html">
            
                <a href="HiveBase.html">
            
                    
                    Hive基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" >
            
                <span>
            
                    
                    数仓总结
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../chapter5/数仓基础.html">
            
                <a href="../chapter5/数仓基础.html">
            
                    
                    数仓理论
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../chapter5/数仓面试题.html">
            
                <a href="../chapter5/数仓面试题.html">
            
                    
                    题目汇总]
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Hive基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="hive-&#x603B;&#x7ED3;">Hive &#x603B;&#x7ED3;</h1>
<h2 id="hive-&#x548C;&#x6570;&#x636E;&#x5E93;&#x6BD4;&#x8F83;">Hive &#x548C;&#x6570;&#x636E;&#x5E93;&#x6BD4;&#x8F83;</h2>
<p>Hive &#x548C;&#x6570;&#x636E;&#x5E93;&#x9664;&#x4E86;&#x62E5;&#x6709;&#x7C7B;&#x4F3C;&#x7684;&#x67E5;&#x8BE2;&#x8BED;&#x8A00;&#xFF0C;&#x5176;&#x4ED6;&#x90FD;&#x4E0D;&#x540C;&#x3002;</p>
<p>1&#xFF09;&#x6570;&#x636E;&#x5B58;&#x50A8;&#x4F4D;&#x7F6E;
Hive &#x5B58;&#x50A8;&#x5728; HDFS &#x3002;&#x6570;&#x636E;&#x5E93;&#x5C06;&#x6570;&#x636E;&#x4FDD;&#x5B58;&#x5728;&#x5757;&#x8BBE;&#x5907;&#x6216;&#x8005;&#x672C;&#x5730;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x4E2D;&#x3002;
2&#xFF09;&#x6570;&#x636E;&#x66F4;&#x65B0;
Hive &#x4E2D;&#x4E0D;&#x5EFA;&#x8BAE;&#x5BF9;&#x6570;&#x636E;&#x7684;&#x6539;&#x5199;&#x3002;&#x800C;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x7684;&#x6570;&#x636E;&#x901A;&#x5E38;&#x662F;&#x9700;&#x8981;&#x7ECF;&#x5E38;&#x8FDB;&#x884C;&#x4FEE;&#x6539;&#x7684;&#xFF0C;
3&#xFF09;&#x6267;&#x884C;&#x5EF6;&#x8FDF;
Hive &#x6267;&#x884C;&#x5EF6;&#x8FDF;&#x8F83;&#x9AD8;&#x3002;&#x6570;&#x636E;&#x5E93;&#x7684;&#x6267;&#x884C;&#x5EF6;&#x8FDF;&#x8F83;&#x4F4E;&#x3002;&#x5F53;&#x7136;&#xFF0C;&#x8FD9;&#x4E2A;&#x662F;&#x6709;&#x6761;&#x4EF6;&#x7684;&#xFF0C;&#x5373;&#x6570;&#x636E;&#x89C4;&#x6A21;&#x8F83;&#x5C0F;&#xFF0C;&#x5F53;&#x6570;&#x636E;&#x89C4;&#x6A21;&#x5927;&#x5230;&#x8D85;&#x8FC7;&#x6570;&#x636E;&#x5E93;&#x7684;&#x5904;&#x7406;&#x80FD;&#x529B;&#x7684;&#x65F6;&#x5019;&#xFF0C;Hive &#x7684;&#x5E76;&#x884C;&#x8BA1;&#x7B97;&#x663E;&#x7136;&#x80FD;&#x4F53;&#x73B0;&#x51FA;&#x4F18;&#x52BF;&#x3002;
4&#xFF09;&#x6570;&#x636E;&#x89C4;&#x6A21;
Hive &#x652F;&#x6301;&#x5F88;&#x5927;&#x89C4;&#x6A21;&#x7684;&#x6570;&#x636E;&#x8BA1;&#x7B97;&#xFF1B;&#x6570;&#x636E;&#x5E93;&#x53EF;&#x4EE5;&#x652F;&#x6301;&#x7684;&#x6570;&#x636E;&#x89C4;&#x6A21;&#x8F83;&#x5C0F;&#x3002;</p>
<h2 id="&#x5185;&#x90E8;&#x8868;&#x548C;&#x5916;&#x90E8;&#x8868;">&#x5185;&#x90E8;&#x8868;&#x548C;&#x5916;&#x90E8;&#x8868;</h2>
<ol>
<li><p>&#x7BA1;&#x7406;&#x8868;&#xFF1A;&#x5F53;&#x6211;&#x4EEC;&#x5220;&#x9664;&#x4E00;&#x4E2A;&#x7BA1;&#x7406;&#x8868;&#x65F6;&#xFF0C;Hive &#x4E5F;&#x4F1A;&#x5220;&#x9664;&#x8FD9;&#x4E2A;&#x8868;&#x4E2D;&#x6570;&#x636E;&#x3002;&#x7BA1;&#x7406;&#x8868;&#x4E0D;&#x9002;&#x5408;&#x548C;
&#x5176;&#x4ED6;&#x5DE5;&#x5177;&#x5171;&#x4EAB;&#x6570;&#x636E;&#x3002;</p>
</li>
<li><p>&#x5916;&#x90E8;&#x8868;&#xFF1A;&#x5220;&#x9664;&#x8BE5;&#x8868;&#x5E76;&#x4E0D;&#x4F1A;&#x5220;&#x9664;&#x6389;&#x539F;&#x59CB;&#x6570;&#x636E;&#xFF0C;&#x5220;&#x9664;&#x7684;&#x662F;&#x8868;&#x7684;&#x5143;&#x6570;&#x636E;</p>
</li>
</ol>
<h2 id="4-&#x4E2A;-by-&#x533A;&#x522B;">4 &#x4E2A; By &#x533A;&#x522B;</h2>
<ol>
<li>Sort By&#xFF1A;&#x5206;&#x533A;&#x5185;&#x6709;&#x5E8F;&#xFF1B;</li>
<li>Order By&#xFF1A;&#x5168;&#x5C40;&#x6392;&#x5E8F;&#xFF0C;&#x53EA;&#x6709;&#x4E00;&#x4E2A; Reducer&#xFF1B;</li>
<li>Distrbute By&#xFF1A;&#x7C7B;&#x4F3C; MR &#x4E2D; Partition&#xFF0C;&#x8FDB;&#x884C;&#x5206;&#x533A;&#xFF0C;&#x7ED3;&#x5408; sort by &#x4F7F;&#x7528;&#x3002;</li>
<li>Cluster By&#xFF1A;&#x5F53; Distribute by &#x548C; Sorts by &#x5B57;&#x6BB5;&#x76F8;&#x540C;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;Cluster by &#x65B9;&#x5F0F;&#x3002;</li>
</ol>
<blockquote>
<p>Cluster by &#x9664;&#x4E86;&#x5177;&#x6709; Distribute by &#x7684;&#x529F;&#x80FD;&#x5916;&#x8FD8;&#x517C;&#x5177; Sort by &#x7684;&#x529F;&#x80FD;&#x3002;&#x4F46;&#x662F;&#x6392;&#x5E8F;&#x53EA;&#x80FD;&#x662F;&#x5347;&#x5E8F;&#x6392;&#x5E8F;&#xFF0C;&#x4E0D;&#x80FD;&#x6307;&#x5B9A;&#x6392;&#x5E8F;&#x89C4;&#x5219;&#x4E3A; ASC &#x6216;&#x8005; DESC&#x3002;</p>
</blockquote>
<h2 id="&#x7A97;&#x53E3;&#x51FD;&#x6570;">&#x7A97;&#x53E3;&#x51FD;&#x6570;</h2>
<ul>
<li>RANK() &#x6392;&#x5E8F;&#x76F8;&#x540C;&#x65F6;&#x4F1A;&#x91CD;&#x590D;&#xFF0C;&#x603B;&#x6570;&#x4E0D;&#x4F1A;&#x53D8;</li>
<li>DENSE_RANK() &#x6392;&#x5E8F;&#x76F8;&#x540C;&#x65F6;&#x4F1A;&#x91CD;&#x590D;&#xFF0C;&#x603B;&#x6570;&#x4F1A;&#x51CF;&#x5C11;</li>
<li>ROW_NUMBER() &#x4F1A;&#x6839;&#x636E;&#x987A;&#x5E8F;&#x8BA1;&#x7B97;</li>
<li>OVER()&#xFF1A;&#x6307;&#x5B9A;&#x5206;&#x6790;&#x51FD;&#x6570;&#x5DE5;&#x4F5C;&#x7684;&#x6570;&#x636E;&#x7A97;&#x53E3;&#x5927;&#x5C0F;&#xFF0C;&#x8FD9;&#x4E2A;&#x6570;&#x636E;&#x7A97;&#x53E3;&#x5927;&#x5C0F;&#x53EF;&#x80FD;&#x4F1A;&#x968F;&#x7740;&#x884C;&#x7684;&#x53D8;&#x800C;&#x53D8;&#x5316;</li>
<li>CURRENT ROW&#xFF1A;&#x5F53;&#x524D;&#x884C;</li>
<li>n PRECEDING&#xFF1A;&#x5F80;&#x524D; n &#x884C;&#x6570;&#x636E;</li>
<li>n FOLLOWING&#xFF1A;&#x5F80;&#x540E; n &#x884C;&#x6570;&#x636E;</li>
<li>UNBOUNDED &#xFF1A; &#x8D77; &#x70B9; &#xFF0C; UNBOUNDED PRECEDING &#x8868; &#x793A; &#x4ECE; &#x524D; &#x9762; &#x7684; &#x8D77; &#x70B9;  UNBOUNDED FOLLOWING &#x8868;&#x793A;&#x5230;&#x540E;&#x9762;&#x7684;&#x7EC8;&#x70B9;</li>
<li>LAG(col,n)&#xFF1A;&#x5F80;&#x524D;&#x7B2C; n &#x884C;&#x6570;&#x636E;</li>
<li>LEAD(col,n)&#xFF1A;&#x5F80;&#x540E;&#x7B2C; n &#x884C;&#x6570;&#x636E;</li>
<li>NTILE(n)&#xFF1A;&#x628A;&#x6709;&#x5E8F;&#x5206;&#x533A;&#x4E2D;&#x7684;&#x884C;&#x5206;&#x53D1;&#x5230;&#x6307;&#x5B9A;&#x6570;&#x636E;&#x7684;&#x7EC4;&#x4E2D;&#xFF0C;&#x5404;&#x4E2A;&#x7EC4;&#x6709;&#x7F16;&#x53F7;&#xFF0C;&#x7F16;&#x53F7;&#x4ECE; 1 &#x5F00;
&#x59CB;&#xFF0C;&#x5BF9;&#x4E8E;&#x6BCF;&#x4E00;&#x884C;&#xFF0C;NTILE &#x8FD4;&#x56DE;&#x6B64;&#x884C;&#x6240;&#x5C5E;&#x7684;&#x7EC4;&#x7684;&#x7F16;&#x53F7;&#x3002;&#x6CE8;&#x610F;&#xFF1A;n &#x5FC5;&#x987B;&#x4E3A; int &#x7C7B;&#x578B;&#x3002;</li>
</ul>
<h2 id="&#x81EA;&#x5B9A;&#x4E49;udf&#x3001;udtf">&#x81EA;&#x5B9A;&#x4E49;UDF&#x3001;UDTF</h2>
<p>&#x5728;&#x9879;&#x76EE;&#x4E2D;&#x662F;&#x5426;&#x81EA;&#x5B9A;&#x4E49;&#x8FC7; UDF&#x3001;UDTF &#x51FD;&#x6570;&#xFF0C;&#x4EE5;&#x53CA;&#x7528;&#x4ED6;&#x4EEC;&#x5904;&#x7406;&#x4E86;&#x4EC0;&#x4E48;&#x95EE;&#x9898;&#xFF0C;&#x53CA;&#x81EA;&#x5B9A;&#x4E49;&#x6B65;
&#x9AA4;&#xFF1F;
1&#xFF09;&#x81EA;&#x5B9A;&#x4E49;&#x8FC7;&#x3002;
2&#xFF09;&#x7528; UDF &#x51FD;&#x6570;&#x89E3;&#x6790;&#x516C;&#x5171;&#x5B57;&#x6BB5;&#xFF1B;&#x7528; UDTF &#x51FD;&#x6570;&#x89E3;&#x6790;&#x4E8B;&#x4EF6;&#x5B57;&#x6BB5;&#x3002;
&#x81EA;&#x5B9A;&#x4E49; UDF&#xFF1A;&#x7EE7;&#x627F; UDF&#xFF0C;&#x91CD;&#x5199; evaluate &#x65B9;&#x6CD5;
&#x81EA;&#x5B9A;&#x4E49; UDTF&#xFF1A;&#x7EE7;&#x627F;&#x81EA; GenericUDTF&#xFF0C;&#x91CD;&#x5199; 3 &#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;initialize(&#x81EA;&#x5B9A;&#x4E49;&#x8F93;&#x51FA;&#x7684;&#x5217;&#x540D;&#x548C;&#x7C7B;
&#x578B;)&#xFF0C;process&#xFF08;&#x5C06;&#x7ED3;&#x679C;&#x8FD4;&#x56DE; forward(result)&#xFF09;&#xFF0C;close
&#x4E3A;&#x4EC0;&#x4E48;&#x8981;&#x81EA;&#x5B9A;&#x4E49; UDF/UDTF&#xFF0C;&#x56E0;&#x4E3A;&#x81EA;&#x5B9A;&#x4E49;&#x51FD;&#x6570;&#xFF0C;&#x53EF;&#x4EE5;&#x81EA;&#x5DF1;&#x57CB;&#x70B9; Log &#x6253;&#x5370;&#x65E5;&#x5FD7;&#xFF0C;&#x51FA;&#x9519;&#x6216;
&#x8005;&#x6570;&#x636E;&#x5F02;&#x5E38;&#xFF0C;&#x65B9;&#x4FBF;&#x8C03;&#x8BD5;.</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Hive基础","level":"1.4.1","depth":2,"next":{"title":"数仓总结","level":"1.5","depth":1,"ref":"","articles":[{"title":"数仓理论","level":"1.5.1","depth":2,"path":"chapter5/数仓基础.md","ref":"chapter5/数仓基础.md","articles":[]},{"title":"题目汇总]","level":"1.5.2","depth":2,"path":"chapter5/数仓面试题.md","ref":"chapter5/数仓面试题.md","articles":[]}]},"previous":{"title":"Hive总结","level":"1.4","depth":1,"ref":"","articles":[{"title":"Hive基础","level":"1.4.1","depth":2,"path":"chapter4/HiveBase.md","ref":"chapter4/HiveBase.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":[],"pluginsConfig":{"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapter4/HiveBase.md","mtime":"2021-03-30T00:41:10.170Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-03-30T00:41:16.128Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

